package com.peihua.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peihua.domain.Result;
import com.peihua.domain.SearchRecommend;
import com.peihua.service.SearchRecommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/recommend")
public class SearchRecommendController {

    @Autowired
    private SearchRecommendService searchRecommendService;

    /**
     * 随机返回 size 条搜索推荐（默认8条）
     */
    @GetMapping("/random")
    public Result random(){
        QueryWrapper<SearchRecommend> qw = new QueryWrapper<>();
        qw.last("ORDER BY RAND() LIMIT 8");
        List<SearchRecommend> list = searchRecommendService.list(qw);
        return Result.success(list);
    }
}
